package com.learn.micro_mall.domain.service.goods;

import com.learn.micro_mall.domain.entity.goods.GoodsSkuParamEntity;
import com.learn.micro_mall.domain.vo.goods.GoodsSkuParamId;
import com.learn.micro_mall.repository.goods.GoodsSkuParamRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class GoodsSkuParamValidatorDomainService {

    @Resource
    private GoodsSkuParamRepository goodsSkuParamRepository;

    public void validatorSkuParamNoExist(GoodsSkuParamId goodsSkuParamId) throws Exception {
        GoodsSkuParamEntity goodsSkuParamEntity = goodsSkuParamRepository.getByGoodsSkuParamId(goodsSkuParamId);
        if(goodsSkuParamEntity != null){
            throw new Exception("已经存在该属性值,请不要重复创建");
        }
    }

    public void validatorSkuParamExist(GoodsSkuParamId goodsSkuParamId) throws Exception {
        GoodsSkuParamEntity goodsSkuParamEntity = goodsSkuParamRepository.getByGoodsSkuParamId(goodsSkuParamId);
        if(goodsSkuParamEntity == null){
            throw new Exception("不存在该属性值");
        }
    }
}
